﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FillMyMug
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Main : Window
    {
        ConfigurationInformation _configurationInfo = new ConfigurationInformation();

        public Main()
        {
            InitializeComponent();
        }


        private void DragWindow(Object sender, MouseButtonEventArgs mba) {
            DragMove();
        }


        private void cupImage_Drop(object sender, DragEventArgs e)
        {

            Cursor oldCursor = this.Cursor;

            e.Handled = true;
            
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {


                this.Cursor = Cursors.Wait;

                ConfigurationInformation config = new ConfigurationInformation();
                if (String.IsNullOrEmpty(config.userName) || String.IsNullOrEmpty(config.userPassword))
                {
                    MessageBox.Show("You must enter configuration inforamtion", "Invalid config", MessageBoxButton.OK);
                    ConfigurationWindow cw = new ConfigurationWindow(_configurationInfo);
                    cw.ShowDialog();
                    this.Cursor = oldCursor;
                    return;
                }

                try
                {

                    SmugMugApiWrapper.SmugMugApi api = new SmugMugApiWrapper.SmugMugApi(_configurationInfo.userName, _configurationInfo.userPassword);

                    string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];
                    List<string> files = new List<string>(fileNames);
                    SmugMugApiWrapper.PostPicturesToSmugMugArguments args = new SmugMugApiWrapper.PostPicturesToSmugMugArguments();
                    args.AlbumName = _configurationInfo.defaultAlbum;

                    api.PostPicturesToSmugMug(files, args);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(),"Error!",MessageBoxButton.OK,MessageBoxImage.Error);

                }

                this.Cursor = oldCursor;

            }

        }

        private void cupImage_DragEnter(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
            
        }

        private void cupImage_DragLeave(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;
            e.Handled = true;

        }

        private void exitAppButton_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown(0);
        }

        private void configurationButton_Click(object sender, RoutedEventArgs e)
        {
            ConfigurationWindow cw = new ConfigurationWindow(_configurationInfo);
            cw.Owner = this;
            cw.ShowDialog();
        }

      
    }
}
